import {
	requestNoAuth,
	request
} from '../../lib/java110/java110Request.js';
import url from '../../constant/url.js';

import {getJson,saveJson} from '../../lib/java110/utils/StorageUtil.js'

const COMMUNITY = "HC_MALL_COMMUNITY"

/**
 * 获取小区ID
 */
export function getCommunityId(){	
	let _communityInfo = getJson(COMMUNITY);
	if(_communityInfo){
		return _communityInfo.communityId;
	}

	let community = uni.getStorageSync("_selectCommunity");
	if(community){
		return community.communityId;
	}
	
	let _systemConfig = uni.getStorageSync('java110SystemConfig');
	if(_systemConfig){
		return _systemConfig.defaultCommunityId;
	}
	return null;
}

/**
 * 获取小区名称
 */
export function getCommunityById(communityId){
	return new Promise((resolve, reject) => {
		requestNoAuth({
			url: url.queryCommunity,
			method: "GET",
			data: {communityId:communityId},
			success: function(res) {
				resolve(res.data.data);
				return ;
			},
			fail: function(res) {
				reject(res);
			}
		});
	})
}

/**
 * 获取小区信息
 */
export function getCommunity(){	
	let _communityInfo = getJson(COMMUNITY);
	if(_communityInfo){
		return _communityInfo;
	}
	return null;
}

/**
 * 查询小区列表
 */
export function getCommunitys(dataObj){
	return new Promise(
		(resolve, reject) => {
		requestNoAuth({
			url: url.listCommunitys,
			method: "GET",
			data: dataObj,
			success: function(res) {
				resolve(res.data);
				return ;
			},
			fail: function(res) {
				reject(res);
			}
		});
	})
}

/**
 * 查询列表街道
 */
export function getCityArea(dataObj){
	return new Promise(
		(resolve, reject) => {
		requestNoAuth({
			url: url.areaUrl,
			method: "GET",
			data: dataObj,
			success: function(res) {
				resolve(res.data);
				return ;
			},
			fail: function(res) {
				reject(res);
			}
		});
	})
}


